package com.ruoyi.hotel.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.hotel.service.IDeviceInfoService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hotel.domain.RepairManage;
import com.ruoyi.hotel.service.IRepairManageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维修管理Controller
 * 
 * @author zd
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/hotel/repair")

public class RepairManageController extends BaseController
{
    @Autowired
    private IRepairManageService repairManageService;

    @Autowired
    private IDeviceInfoService deviceInfoService;

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 查询维修管理列表
     */
//    @PreAuthorize("@ss.hasPermi('hotel:repair:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(RepairManage repairManage)
    {
        startPage();
        List<RepairManage> list = repairManageService.selectRepairManageList(repairManage);
        return getDataTable(list);
    }

    /**
     * 查询维修管理列表
     */

    @GetMapping("/manageList")
    @Anonymous
    public TableDataInfo manageList(RepairManage repairManage)
    {
        startPage();
        List<RepairManage> list = repairManageService.manageList(repairManage);
        return getDataTable(list);
    }

    /**
     * 查询维修管理列表
     */

    @GetMapping("/studentViewList")
    @Anonymous
    public TableDataInfo studentViewList(RepairManage repairManage)
    {
         startPage();
        List<RepairManage> list = repairManageService.studentViewList(repairManage);
        return getDataTable(list);
    }

    /**
     * 查询维修管理列表
     */

    @GetMapping("/manageUserList")
    @Anonymous
    public TableDataInfo manageUserList(RepairManage repairManage)
    {
        startPage();
        List<RepairManage> list = repairManageService.manageUserList(repairManage);
        return getDataTable(list);
    }

    @GetMapping("/userList")
    @Anonymous
    public List<SysUser> getRepairUser()
    {
        SysUser sysUser = new SysUser();
        sysUser.setDeptId(200L);
        List<SysUser> list = sysUserService.selectUserList(sysUser);
        return list;
    }

    /**
     * 导出维修管理列表
     */
    @Anonymous
    @Log(title = "维修管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RepairManage repairManage)
    {
        List<RepairManage> list = repairManageService.selectRepairManageList(repairManage);
        ExcelUtil<RepairManage> util = new ExcelUtil<RepairManage>(RepairManage.class);
        util.exportExcel(response, list, "维修管理数据");
    }

    /**
     * 获取维修管理详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(repairManageService.selectRepairManageById(id));
    }

    /**
     * 新增维修管理
     */
    @Anonymous
    @Log(title = "维修管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody List<RepairManage> repairManages)
    {
        return toAjax(repairManageService.insertRepairManage(repairManages));
    }

    /**
     * 修改维修管理
     */
    @Anonymous
    @Log(title = "维修管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RepairManage repairManage)
    {
        return toAjax(repairManageService.updateRepairManage(repairManage));
    }

    /**
     * 删除维修管理
     */
    @Anonymous
    @Log(title = "维修管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(repairManageService.deleteRepairManageByIds(ids));
    }

    @GetMapping("/getRepair")
    public List<RepairManage> getrepair()
    {
        List<RepairManage> repairManages = (List<RepairManage>)redisTemplate.opsForValue().get("repairManages");
        return repairManages;
    }
}
